//
//  HomeTableViewController.swift
//  jackWu
//
//  Created by Lewhaming on 2016/11/18.
//  Copyright © 2016年 IQ. All rights reserved.
//

import UIKit

class HomeTableViewController: BaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //1.判断是否登录
        if  !isLogin{
            //设置访客试图
            visitorView?.setupVisitorInfo(imageName: nil, title: "关注一些人，这个里看看有什么惊喜")
        }
        
        setupNav()
        
        //注册通知
        NotificationCenter.default.addObserver(self, selector: #selector(titleChange), name: NSNotification.Name(rawValue: PresentationManagerDidPresented), object: animatorManger)
        
        NotificationCenter.default.addObserver(self, selector: #selector(titleChange), name: NSNotification.Name(rawValue: PresentationManagetDidDismissed), object: animatorManger)
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    @objc private func titleChange(){
    
        titleButton.isSelected = !titleButton.isSelected
    }
    
    //MARK: 初始化导航条
    private func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendattention", target: self, action: #selector(leftClicked))
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop", target:self, action: #selector(rightClicked))
        navigationItem.titleView = titleButton
    }
    
    @objc private func leftClicked(){
        IQLog(message: "mesg")
    }
    
    @objc private func rightClicked(){
        IQLog(message: "right")
    }
    
    @objc private func titleBtnClicked(btn: TitleButton){
        IQLog(message: "佛挡杀佛")
//        btn.isSelected = !btn.isSelected
        
        let sb = UIStoryboard(name: "Popover", bundle: nil)
        
        guard let menuView = sb.instantiateInitialViewController()
        else{
            return
        }
        //自定义转场动画
        //设置转场代理
        
        menuView.transitioningDelegate = animatorManger
        menuView.modalPresentationStyle = UIModalPresentationStyle.custom
        present(menuView, animated: true, completion: nil)

        
    }

//
    
    
    private lazy var titleButton : TitleButton = {
        let btn = TitleButton()
        btn.setTitle("吴昌景", for: UIControlState.normal)
        btn.addTarget(self, action: #selector(titleBtnClicked(btn:)), for: UIControlEvents.touchUpInside)
    
        return btn
    }()
 
    private lazy var animatorManger : WCJPresentationMessage = { () -> WCJPresentationMessage in
        let manager = WCJPresentationMessage()
        manager.presentFrame = CGRect(x: 100, y: 45, width: 200, height: 300)
        return manager
    }()
}



